package com.example.week10_spring_security.entity;

import com.example.week10_spring_security.utils.StringListConverter;
import lombok.*;
import org.hibernate.Hibernate;

import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.Id;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Getter
@Setter
@ToString
@Entity
public class Role {
    @Id
    String name;

    private String remark;

    @Convert(converter = StringListConverter.class)
    private List<String> authorities = new ArrayList<>();

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || Hibernate.getClass(this) != Hibernate.getClass(o)) return false;
        Role role = (Role) o;
        return name != null && Objects.equals(name, role.name);
    }

    @Override
    public int hashCode() {
        return getClass().hashCode();
    }
}

